package com.hctforgreen.greenservice.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.hctforgreen.greenservice.R;

import android.app.Activity;
import android.widget.Switch;
import android.widget.Toast;

/**
 * 冷媒计算工具类
 * @author wuhs 20160111
 *
 */
public class RefrigerantCalculatorUtil {
	
	static double[] b = {0.680,0.520,0.350,0.250,0.170,0.110,0.054,0.022};//连接管液管长度对应的   单位冷媒追加量  kg/m
	
	static double[][] a224 = {{0,0.5,1.0,2.0},{0.5,1.0,2.0,3.5}};//22.4
	static double[][] a250 = {{0,0.5,1.0,2.0},{0.5,1.0,2.0,3.5}};//25.0
	static double[][] a252 = {{0,0.5,1.0,2.0},{0.5,1.0,2.0,3.5}};//25.2
	static double[][] a280 = {{0,0.5,1.0,2.0},{0.5,1.0,2.0,3.5}};//28.0
	static double[][] a300 = {{0,0.5,1.0,2.0},{0.5,1.0,2.0,3.5}};//30.0
	static double[][] a335 = {{0,1.0,1.5,2.5},{0.5,1.5,3.0,4.0}};//33.5
	static double[][] a350 = {{0,1.0,1.5,2.5},{0.5,1.5,3.0,4.0}};//35.0
	static double[][] a400 = {{0,1.5,2.0,3.0},{0.5,2.0,3.5,5.0}};//40.0
	static double[][] a450 = {{0,1.5,2.0,3.0},{0.5,2.0,3.5,5.0}};//45.0
	static double[][] a504 = {{0,1.5,2.5,3.5},{0.5,2.5,4.0,5.5}};//50.4
	static double[][] a560 = {{0,2.0,3.0,4.0},{1.0,3.0,4.5,6.0}};//56.0
	static double[][] a615 = {{0,2.0,3.5,4.0},{1.5,3.5,5.0,6.0}};//61.5
	static double[][] a785 = {{0,3.0,4.0,5.0},{2.0,3.5,5.0,7.0}};//78.5
	static double[][] a900 = {{0,3.0,4.0,6.0},{2.0,4.0,6.0,8.0}};//90.0
	
	
	/*
	 * A[x][y][z]:  x为室外机容量，y为内机配置数量是否>4,z为容量配置率
	 * 例子：A[0][0][0]：室外机容量22.4，内机配置数量是否<4,容量配置率50%≤C≤70%,值为0
	 */
	static double[][][] A_5S = {a224,a252,a280,a335,a400,a450,a504,a560,a615};//GMV5S系列产品
	static double[][][] A_ES = {a250,a300,a350,a400,a450,a615,a785,a900};//GMV5 ES系列产品
	static double[][][] A_TOPS = {a250,a300,a350,a400,a450};//GMV5 TOPS系列产品
	
	
	
	/**
	 * 针对GMV5 ES系列产品侧风机、GMV Star家用多联室外机特殊机型
	 * @param E 为整套系统中Φ6.35液管总长
	 * @param F 为整套系统中Φ9.52液管总长
	 * @param G 为整套系统中Φ12.7液管总长
	 * @return
	 */
	public static double getRefrigerantCount_module_else(double E,double F,double G){
		return G*0.11+F*0.054+E*0.022;
	}
	
	/**
	 * 针对GMV Star家用多联室外机 计算冷媒追加量
	 * @param E 为整套系统中Φ6.35液管总长，单位m
	 * @param F 为整套系统中Φ9.52液管总长，单位m
	 * @return
	 */
	public static double getRefrigerantCount_module4(double F,double E){
		double X = 0;
		if(E + F > 20){
			if(F >= 20){
				X=(F-20)*0.054+E*0.022;
			}else{
				X=(E+F-20)*0.022;
			}
		}
		return X;
	}
	
	/**
	 * 计算连接管冷媒追加量
	 * @param ioConnectionLengthList 连接管长度
	 * @return
	 */
	public static double getRefrigerantCount_B(double[] ioConnectionLengthList){
		double result = 0;
		for (int i = 0; i < 8; i++) {//默认8位
			double ioConnectionLength = ioConnectionLengthList[i];
			result = result + ioConnectionLength * b[i];
		}
		return result;
	}
	
	/**
	 * 计算室外机制冷剂追加量
	 * @param moduleId 室外机系列
	 * @param module_capacity_position 外机模块容量 对应的数组位置
	 * @param inner_count 内机台数
	 * @param rate_position 内外机额定容量配置率 对应的数组位置
	 * @return
	 */
	
	public static double getRefrigerantCount_A(int moduleId, ArrayList<Integer> module_capacity_position,int inner_count,int rate_position){
		double result = 0;
		int y,z = 0;
		z = rate_position;
		if(inner_count>=4){
			y=1;
		}else{
			y=0;
		}
		
		for (Iterator iterator = module_capacity_position.iterator(); iterator.hasNext();) {
			int x = (Integer) iterator.next();
			switch (moduleId) {
			case 1:
				result = result + A_ES[x][y][z];//GMV5 ES系列产品
				break;
			case 2:
				result = result + A_5S[x][y][z];//GMV5S系列产品
				break;
			case 3:
				result = result + A_TOPS[x][y][z];//GMV5 TOPS系列产品
				break;

			default:
				break;
			}
			
		}
		
		return result;
	}
	/**
	 * 内外机额定容量配置率
	 * @param inner_capacityCount 内机容量
	 * @param module_capacity 外机模块容量
	 * @return
	 */
	public static int getRate(Double inner_capacityCount,ArrayList<Double> module_capacity){
		double result=0;//计算得出的比率
		int rate_position=0;//获取比率对应的数组位置
		double module_capacity_sum=0;
		for (int i = 0; i < module_capacity.size(); i++) {
			module_capacity_sum = module_capacity_sum + module_capacity.get(i);
		}
		if(module_capacity_sum!=0){
			result = (inner_capacityCount)/module_capacity_sum;
		}
		
		if(0.5<=result && result<=0.7){
			rate_position = 0;
		}else if(0.7<result && result<=0.9){
			rate_position = 1;
		}else if(0.9<result && result<=1.05){
			rate_position = 2;
		}else if(1.05<result && result<=1.35){
			rate_position = 3;
		}else{
			rate_position = -1;
		}
		
		
		return rate_position;
	}

	
	
	
}
